public class ProxyPattern {
    public static void main(String[] args) {
        TimeProxy man = new TimeProxy(new LogProxy(new Man()));
        man.act();
    }
}

interface Actable {
    void act();
}

class Man implements Actable {

    public void act() {
        System.out.println("run");
    }
}

class TimeProxy implements Actable {
    Actable actable;

    public TimeProxy(Actable actable) {
        this.actable = actable;
    }

    public void act() {
        long time = System.currentTimeMillis();
        actable.act();
        long l = System.currentTimeMillis() - time;
        System.out.println("l = " + l);
    }
}

class LogProxy implements Actable {
    Actable actable;

    public LogProxy(Actable actable) {
        this.actable = actable;
    }

    public void act() {
        System.out.println("before running");
        actable.act();
        System.out.println("after running");
    }
}
